<?php

class Application_Form_ChangePassword extends Zend_Form {

    public function init() {
        /* Form Elements & Other Definitions Here ... */
    }

    public function __construct($auth = null) {

        $this->setDecorators(array('FormElements',
            array('HtmlTag', array('tag' => 'div', 'class' => 'row')),
            'Form')); // supprime la balise <dl>

        $decorators = array(
            'ViewHelper',
            'Errors',
            array('Description', array('tag' => 'p', 'class' => 'description')),
            array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'input')), // 3
            array('Label', array('tag' => null, 'class' => '')), // 2
            array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'clearfix')) // 1) exterieur
        );

        $noDecorators = array('ViewHelper');

        $id_user = new Zend_Form_Element_Hidden('id_user');
        $id_user->addFilter('Int')
                ->addFilter('Null');

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('Mot de passe')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $password_bis = new Zend_Form_Element_Password('password_bis');
        $password_bis->setLabel('Vérification')
                ->setRequired(true)
                ->setDescription('Confirmer votre mot de passe')
                ->addFilter('StringTrim')
                ->addValidator('identical', false, array('token' => 'password'))
                ->addErrorMessage('Les mots de passe ne correspondent pas!')
                ->addValidator('NotEmpty');

        $urlBack = $this->getView()->url(array('controller' => 'user', 'action' => 'edit'));
        $cancel = new Zend_Form_Element_Button('cancel');
        $cancel->setLabel('Annuler')
                ->setAttrib('class', 'btn')
                ->setAttrib('type', 'reset')
                ->setDecorators(array('ViewHelper'))
                ->setAttrib('onclick', 'document.location ="' . $urlBack . '"');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Enregistrer')
                ->setAttrib('id', 'submitbutton')
                ->setAttrib('class', 'btn primary');

        $this->addElements(array($id_user, $password, $password_bis, $submit, $cancel));

        $this->setElementDecorators(array('ViewHelper'), array('submit', 'cancel'));
        $this->setElementDecorators($decorators, array('password', 'password_bis'));
        $this->setElementDecorators($noDecorators, array('id_user'));

        // Buttons Group
        $this->addDisplayGroup(array('cancel', 'submit'), 'buttonGroupe');
        $this->buttonGroupe->removeDecorator('Label');
        $this->buttonGroupe->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div', 'class' => 'actions'))
        ));
    }

}

